﻿using System.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc.Html;
using System.Text;
using Domain.MainModule.Entities;

namespace Presentation.Web.UI.ViewClasses.Dinner
{
    public class MyViewClass : WebViewPage<IEnumerable<Dinners>>
    {
        public MyViewClass()
        {
            HydrateTitle();
        }

        public MyViewClass(HtmlHelper<IEnumerable<Dinners>> htmlHelper)
            : this()
        {
            Html = htmlHelper;
        }

        void HydrateTitle()
        {
            ViewBag.Title = "My Dinners";
        }

        public MvcHtmlString getMyDinners() { return getMyDinners(Model); }

        public MvcHtmlString getMyDinners(IEnumerable<Dinners> dinners)
        {

            var _dinners = Model ?? dinners;
            if (!_dinners.Any())
                return new MvcHtmlString("<li>You don't own or aren't registered for any dinners.</li>");
            var htmlString = new StringBuilder();
            htmlString.Append("<ul data-role=\"listview\" data-inset=\"true\" class=\"ui-listview ui-listview-inset ui-corner-all ui-shadow\">");
            foreach (var dinner in _dinners)
            {
                htmlString.Append("<li data-corners=\"false\" data-shadow=\"false\" data-iconshadow=\"true\" data-wrapperels=\"div\" data-icon=\"arrow-r\" data-iconpos=\"right\" data-theme=\"c\" class=\"ui-btn ui-btn-up-c ui-btn-icon-right ui-li-has-arrow ui-li\">");
                htmlString.Append("<div class=\"ui-btn-inner ui-li\">");
                htmlString.Append("<div class=\"ui-btn-text\">");

                var text = new StringBuilder();
                text.Append(dinner.Title);
                text.Append(" ");
                text.Append(dinner.EventDate.ToString("yyyy-MMM-dd"));
                text.Append(" ");
                text.Append(dinner.EventDate.ToString("HH:mm tt"));
                text.Append(" at ");
                text.Append(string.Format("{0} {1}", dinner.Address, dinner.Country));
                htmlString.Append(Html.ActionLink(text.ToString(), "Details", new { id = dinner.DinnerID }, new { @class = "ui-link-inherit" }));
                htmlString.Append("</div>");
                htmlString.Append("<span class=\"ui-icon ui-icon-arrow-r ui-icon-shadow\">&nbsp;</span></div>");
                htmlString.Append("</li>");
            }
            htmlString.Append("</ul>");
            return new MvcHtmlString(htmlString.ToString());
        }


        public override void Execute()
        {

        }
    }
}